unit Alta_Empleados;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, pngimage, ExtCtrls, GIFImg, Buttons, DB, ADODB, Mask,
  DBCtrls;

type
  TF_AltaEmpleados = class(TForm)
    L_TipoDoc: TLabel;
    L_NroDoc: TLabel;
    L_NombreEmp: TLabel;
    L_ApellidoEmp: TLabel;
    L_DireccionEmp: TLabel;
    L_TelEmp: TLabel;
    L_Tel2Emp: TLabel;
    L_CodPostal: TLabel;
    L_MailEmp: TLabel;
    L_CodEstado: TLabel;
    L_CodHorario: TLabel;
    L_SueldoEmp: TLabel;
    B_Cancel: TButton;
    GB_DatosReqEmp: TGroupBox;
    GB_DatosOpc: TGroupBox;
    B_Accept: TButton;
    BB_CP: TBitBtn;
    BB_CodEst: TBitBtn;
    BB_CodHorario: TBitBtn;
    ADOConnection1: TADOConnection;
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    DataSourceEmpleados: TDataSource;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit6: TDBEdit;
    DBEdit7: TDBEdit;
    DBEdit8: TDBEdit;
    DBEdit9: TDBEdit;
    DBEdit10: TDBEdit;
    DBEdit11: TDBEdit;
    DBEdit12: TDBEdit;
    procedure B_CancelClick(Sender: TObject);
    procedure B_AcceptClick(Sender: TObject);
    procedure DBEdit8Exit(Sender: TObject);
    procedure DBEdit11Exit(Sender: TObject);
    procedure DBEdit10Exit(Sender: TObject);
    procedure BB_CPClick(Sender: TObject);
    procedure BB_CodHorarioClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BB_CodEstClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  F_AltaEmpleados: TF_AltaEmpleados;

implementation

uses Empleados, Localidades, Horarios_Empleados, Estado_Empleados;

{$R *.dfm}

procedure TF_AltaEmpleados.BB_CodEstClick(Sender: TObject);
begin
    F_EstadoEmpleados.Bandera_Seleccionar := True;
    F_EstadoEmpleados.showmodal;
end;

procedure TF_AltaEmpleados.BB_CodHorarioClick(Sender: TObject);
begin
    F_HorariosEmp.Bandera_Seleccionar := True;
    F_HorariosEmp.showmodal;
end;

procedure TF_AltaEmpleados.BB_CPClick(Sender: TObject);
begin
    F_Localidades.Bandera_Seleccionar := True;
    F_Localidades.Llama := 1;
    F_Localidades.showmodal;
end;

procedure TF_AltaEmpleados.B_AcceptClick(Sender: TObject);
begin
{ TRIM() Es para limpiar los espacios en blanco, sino '     ' me lo tomaba como dato }
  if ((TRIM(DBEdit1.Text) = '') OR (TRIM(DBEdit2.Text) = '') OR (TRIM(DBEdit3.Text) = '') OR (TRIM(DBEdit4.Text) = '') OR (TRIM(DBEdit11.Text) = '') OR (TRIM(DBEdit8.Text) = '') OR (TRIM(DBEdit6.Text) = '') OR (TRIM(DBEdit10.Text) = '')) THEN
    ShowMessage('Debe completar todos los datos requeridos.')
  ELSE
  BEGIN
    F_Empleados.T_Buscar.Text := F_Empleados.ADOQuery1NOMBRE_EMPLEADO.Value;
    DataSourceEmpleados.DataSet.Append;
    F_Empleados.B_Buscar.Click;
    DataSourceEmpleados.DataSet.Refresh;
    F_AltaEmpleados.Close;
  END;
end;

procedure TF_AltaEmpleados.B_CancelClick(Sender: TObject);
begin
    DataSourceEmpleados.DataSet.Cancel;
    F_AltaEmpleados.Close;
    DataSourceEmpleados.DataSet.First;
end;

procedure TF_AltaEmpleados.DBEdit10Exit(Sender: TObject);
begin
  if TRIM(Self.DBEdit10.Text) <> '' then
  BEGIN
    ADOQuery1.SQL.Text := 'SELECT * FROM ESTADO_EMPLEADOS WHERE (COD_ESTADO = '+Self.DBEdit10.Text+')';
    ADOQuery1.Open;
    if (BoolToStr(ADOQuery1.IsEmpty) = '-1') then
        BB_CodEst.Click;
  END
  ELSE
     BB_CodEst.Click;
end;

procedure TF_AltaEmpleados.DBEdit11Exit(Sender: TObject);
begin
  if TRIM(Self.DBEdit11.Text) <> '' then
  BEGIN
    ADOQuery1.SQL.Text := 'SELECT * FROM HORARIOS_EMP WHERE (COD_HORARIO = '+Self.DBEdit11.Text+')';
    ADOQuery1.Open;
    if (BoolToStr(ADOQuery1.IsEmpty) = '-1') then
    begin
        BB_CodHorario.Click;
    end
  END
  ELSE
    BB_CodHorario.Click;
end;

procedure TF_AltaEmpleados.DBEdit8Exit(Sender: TObject);
begin
  if TRIM(Self.DBEdit8.Text) <> '' then
  BEGIN
    ADOQuery1.SQL.Text := 'SELECT * FROM LOCALIDADES WHERE (COD_POSTAL = '+Self.DBEdit8.Text+')';
    ADOQuery1.Open;
    if (BoolToStr(ADOQuery1.IsEmpty) = '-1') then
    begin
        BB_CP.Click;
    end
  END
  ELSE
     BB_CP.Click;
end;

procedure TF_AltaEmpleados.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  DataSourceEmpleados.DataSet.Cancel;
end;

end.
